<?php
  include ('header.php');
?>
<head>
<title><?php echo $titles['admin_edit_auditories']?></title>
</head>

<body>
<?php

if($_SESSION['access']<3)
{
DIE('Помилка: Ви не маєте права доступу до сайту:');
}

if ($_GET[del]){
$sql="DELETE FROM auditories where auditory_id='".$_GET[del]."'";  
$process=mysql_query($sql, $db);
}



if (isset($_POST['edit_full_config']) && $_POST['edit_full_config']) {
for ($n = 1; $n <= $_SESSION["count_par"]; $n++) {
$с1="с1".$n;
$с2="с2".$n;
$с3="с3".$n;
$с4="с4".$n;
$с5="с5".$n;
$sql="update auditories 
set auditory_id='".$_POST[$с2]."',
auditory_name='".$_POST[$с3]."' where  auditory_id='".$_POST[$с2]."'";
$process=mysql_query($sql, $db);

}
//$_SESSION[c2_add]=$_POST[c2_add];

if ($_POST[c2_add] && $_POST[c3_add])
{

$sql="insert into auditories
values ('".$_POST[c2_add]."','".$_POST[c3_add]."')";
//echo $sql."<br>";
$process=mysql_query($sql, $db);
$_SESSION[add]=0;
unset ($_SESSION[add]);


}
}
?>
<form name="edit_config"  method="POST" action='<?php echo $_SERVER['PHP_SELF']?>' >
<table class="IND_INVENTORY" width=140>
<tr>

    <td class="IND_INVENTORY_C" width="50">Id</td>
	<td class="IND_INVENTORY_C" width=60>Назва Аудиторії</td>
	<td class="IND_INVENTORY_C" width="30">Дія</td>

</tr>
<?php
$sql="select * from auditories where auditory_id<>0 order by auditory_id";  
$process=mysql_query($sql, $db);
$i=1;
$j=0;
while ($row = mysql_fetch_array($process, $i)){
$j++;
	echo "<tr>";

	echo "<td class=\"IND_INVENTORY_C\"><input type=text  name='с2".$j."' value='".$row[ auditory_id ]."' size=20></td>";
	echo "<td class=\"IND_INVENTORY_C\"><input type=text  name='с3".$j."' value='".$row[ auditory_name ]."' size=60></td>";

	echo "<td class=\"IND_INVENTORY_C\"><a href='".$_SERVER['PHP_SELF']."?del=".$row[auditory_id]."' onClick=\"return confirm('".$messages[config_name_delete].$row[config_name]."?');\"><img src=images/delete.png	border=0  width=20 height=20 onMouseOver=\"toolTip('".$actions['delete']."')\" onMouseOut=\"toolTip()\"></img></a></td>";
	echo "</tr>";
}
$sql="select max(auditory_id) as max from auditories where auditory_id<>0 order by auditory_id";  
$process=mysql_query($sql, $db);
$i=1;

$row = mysql_fetch_array($process, $i);
$next=$row[max]+1;
$_SESSION["count_par"]=$j;
echo "<tr>";
	echo "<td class=\"IND_INVENTORY_C\"><input type=text  name='c2_add'  size=20 value=".$next ."></td>";
	echo "<td class=\"IND_INVENTORY_C\"><input type=text  name='c3_add'  size=60></td>";

	echo "<td class=\"IND_INVENTORY_C\" width=5></td>";
	echo "</tr><div id=\"floatTip\"></div>";
?>
<tr><td colspan="6" ><input type="submit" value="<?php echo $texts[save] ?>" name="edit_full_config"></td></tr>
</table>

</form>
</body>
<?php
  include ('footer.php');
?>